import { getDataScreen, getAreaCancerCount, getHospitalDataInit, getCityByHospital } from "@/services/dataScreenApi";

export default {
  namespace: "dataScreen",

  state: {
    data: {
      list: [], pagination: {}
    }, // 需要显示详情的数据
    record: {},
    hospitalMapData: {},
  },

  effects: {
    *getDataScreen({ payload }, { call, put }) {
      const response = yield call(getDataScreen, payload);
      return response;
    },
    *getAreaCancerCount({ payload }, { call, put }) {
      const response = yield call(getAreaCancerCount, payload);
      return response;
    },


    *getHospitalDataInit({ payload }, { call, put }) {
      const response = yield call(getHospitalDataInit, payload);
      return response;
    },
    *getCityByHospital({ payload }, { call, put }) {
      const response = yield call(getCityByHospital, payload);
      yield put({
        type: 'savehospitalMapData',
        payload: response.data
      })

      return response;
    },

  },

  reducers: {
    // 
    savehospitalMapData(state, action) {

      const city = action.payload.city

      const hospitalMapData = {}
      city.forEach(element => {
        hospitalMapData[element.city_code] = element.org
      });
      return {
        ...state,
        hospitalMapData
      };
    },

  }
};
